package com.jeff.tianti.cms.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.Company;
import com.jeff.tianti.cms.dto.CompanyQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xujianfang
 * @desc CompanyDaoImpl��
 * @date 2019-07-15
 */

public class CompanyDaoImpl extends CustomBaseSqlDaoImpl implements CompanyDaoCustom {

    public PageModel<Company> queryCompanyPage(CompanyQueryDTO companyQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append(" select t from Company t where 1 = 1 ");
        if (companyQueryDTO != null) {
            String auditFlag = companyQueryDTO.getAuditFlag();
            if (StringUtils.isNotBlank(auditFlag) && !"-1".equals(auditFlag)) {
                hql.append(" and t.auditFlag = :auditFlag ");
                map.put("auditFlag", auditFlag);
            }
            String identification = companyQueryDTO.getIdentification();
            if (StringUtils.isNotBlank(identification)) {
                hql.append(" order by t.updateDate desc ");
            } else {
                hql.append(" order by t.createDate desc ");
            }

        }
        return this.queryForPageWithParams(hql.toString(), map, companyQueryDTO.getCurrentPage(), companyQueryDTO.getPageSize());
    }

    public List<Company> queryCompanyList(CompanyQueryDTO companyQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Company t ");
        return this.queryByMapParams(hql.toString(), map);
    }


}